﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace Freshome.p.fox
{
    public static class PageLinkHelper
    {
        public static MvcHtmlString PageLinks(this HtmlHelper html, Models.Pagentry pageInfo, Func<int, string> pageUrl, string classtyle)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 1; i <= pageInfo.TotalPages; i++)
            {
                if (i == pageInfo.CurrentPage)
                {
                    TagBuilder tag = new TagBuilder("span");
                    tag.InnerHtml = i.ToString();
                    result.Append(tag.ToString());
                }
                else
                {
                    TagBuilder tag = new TagBuilder("a"); // Construct an <a> tag
                    tag.MergeAttribute("href", pageUrl(i));
                    tag.InnerHtml = i.ToString();
                    tag.AddCssClass(classtyle);
                    result.Append(tag.ToString());
                }
            }
            return MvcHtmlString.Create(result.ToString());
        }
    }
}